 /**
   * Copyright 2014 Viettel Telecom. All rights reserved.
   * VIETTEL PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
   */
 package com.viettel.core.dao.cms; 
import java.util.ArrayList; 
import java.util.List; 

import org.hibernate.type.StandardBasicTypes; 
import org.hibernate.type.Type; 
import org.springframework.beans.factory.annotation.Autowired; 

import com.viettel.core.exceptions.DataAccessException; 
import com.viettel.core.entities.cms.ArticleCategory;
import com.viettel.core.entities.cms.MultiMediaItem;
import com.viettel.core.enumtype.ArticleCategoryStatus;
import com.viettel.core.enumtype.MultiMediaItemStatus;
import com.viettel.core.repo.IRepository;
 /**
   *  Mo ta muc dich cua lop (interface)
   *  @author: TOANTM1
   *  @version:  
   *  @since: 28/02/2014 - 10:38:42
   */
 public class MultiMediaItemDAOImpl implements MultiMediaItemDAO { 
	 private IRepository repo; 
		
	 	public void setRepo(IRepository repo) {
			this.repo = repo;
		}
 
 	/**@author TOANTM1
  	 * 28/02/2014 - 10:38:42
  	 * For: 
  	 * @description: 
  	 */
 	@Override 
	public MultiMediaItem getMultiMediaItemById(Integer id) throws DataAccessException { 
		return repo.getEntityById(MultiMediaItem.class, id); 
	} 
 
 	/**@author TOANTM1
  	 * 28/02/2014 - 10:38:42
  	 * For: 
  	 * @description: 
  	 */
 	@Override 
	public MultiMediaItem createMultiMediaItem(MultiMediaItem multimediaitem) 
			throws DataAccessException { 
		if (multimediaitem == null) { 
			throw new IllegalArgumentException("multimediaitem"); 
		} 
		repo.create(multimediaitem); 
		return repo.getEntityById(MultiMediaItem.class, multimediaitem.getId()); 
	} 
 
 	/**@author TOANTM1
  	 * 28/02/2014 - 10:38:42
  	 * For: 
  	 * @description: 
  	 */
 	@Override 
	public void updateMultiMediaItem(MultiMediaItem multimediaitem) throws DataAccessException { 
		if (multimediaitem == null) { 
			throw new IllegalArgumentException("multimediaitem"); 
		} 
		repo.update(multimediaitem); 
	} 
 
 	/**@author TOANTM1
  	 * 28/02/2014 - 10:38:42
  	 * For: 
  	 * @description: 
  	 */
 	@Override 
	public void deleteMultiMediaItem(MultiMediaItem multimediaitem) throws DataAccessException { 
		if (multimediaitem == null) { 
			throw new IllegalArgumentException("multimediaitem"); 
		} 
		repo.delete(multimediaitem); 
	} 
 	
 	@Override
	public List<MultiMediaItem> getListMultiMediaByObject(Integer objectType, Integer objectId, Integer type)
			throws DataAccessException {
		List<Object> params = new ArrayList<Object>();
		String sql = "select * from Multi_Media_Item where status != ? AND object_type = ? AND object_id = ? AND type = ? ";
		
		params.add(MultiMediaItemStatus.DELETED.getValue());
		
		params.add(objectType);
		
		params.add(objectId);
		
		params.add(type);
		
		sql += " ORDER BY created_time DESC ";
		return repo.getListBySQL(MultiMediaItem.class, sql, params);
	} 
} 
 
